# __author__ = 'heyin'
# __date__ = '2018/11/9 11:09'
# mktime和localtime互为转换
import time


def timestamp2datetime(timestamp):
    # 时间戳转日期时间格式
    # 34592400   北京时间1971-02-05 17:00:00
    # timestamp = 1541687400  # 2018-11-08 22:30:00
    time_array = time.localtime(timestamp)
    datetime = time.strftime("%Y-%m-%d %H:%M:%S", time_array)  # 字符串
    return datetime


def datetime2timestamp(datetime):
    # 日期时间格式转时间戳
    # datetime = '2018-11-08 22:30:00'
    timestamp = int(time.mktime(time.strptime(datetime, '%Y-%m-%d %H:%M:%S')))
    return timestamp


def timestamp2date(timestamp):
    time_array = time.localtime(timestamp)
    date = time.strftime("%Y-%m-%d", time_array)  # 字符串
    return date


if __name__ == '__main__':
    ret = datetime2timestamp('2014-10-5 22:30:00')
    print(ret)
    print(time.time())
    ret = timestamp2datetime(1542233759)
    print(ret)